﻿using Microsoft.Extensions.Caching.Memory;

namespace Medlcalcare.MVC.Servicesa
{
    public interface ICacheServicea
    {
        /// <summary>
        /// 获取或创建缓存项（支持异步）
        /// </summary>
        /// <typeparam name="TItem">缓存对象类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="factory">缓存项创建工厂</param>
        /// <param name="expiration">过期时间（默认20分钟）</param>
        TItem GetOrCreate<TItem>(string key, Func<ICacheEntry, TItem> factory, TimeSpan? expiration = null);

        /// <summary>
        /// 设置缓存项
        /// </summary>
        /// <typeparam name="TItem">缓存对象类型</typeparam>
        void Set<TItem>(string key, TItem value, TimeSpan? expiration = null);

        /// <summary>
        /// 获取缓存项
        /// </summary>
        /// <typeparam name="TItem">缓存对象类型</typeparam>
        TItem Get<TItem>(string key);

        /// <summary>
        /// 移除缓存项
        /// </summary>
        void Remove(string key);

        /// <summary>
        /// 检查是否存在缓存项
        /// </summary>
        bool Exists(string key);
    }
}
